home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1994 November / macformat-018.iso / Utility Spectacular / Developer / SAT / SAT Lib ƒ / SAT.p next >
Encoding:
Text File  |  1994-07-26  |  9.4 KB  |  210 lines  |  [TEXT/PJMM]

  1. unit SAT;
  2.  
  3. interface
  4.  
  5.     type
  6.         {BMPtr = ^BitMap;}
  7.  
  8.         FacePtr = ^Face;
  9.         Face = record
  10.                 colorData: Ptr;
  11.                 resNum: integer;
  12.                 iconMask: BitMap;
  13.                 rowBytes: integer;
  14.                 next: FacePtr;
  15.                 maskRgn: RgnHandle;
  16.             end;
  17.  
  18.         SpritePtr = ^Sprite;
  19.         Sprite = record
  20. { Variables that you should change as appropriate }
  21.                 kind: Integer; { Used for identification. >0: friend. <0 foe }
  22.                 position: Point;
  23.                 hotRect, hotRect2: Rect; { Tells how large the sprite is; hotRect is centered around origo }
  24.                                         {hotRect is set by you. hotRect2 is offset to the current position.}
  25.                 face: FacePtr; { Pointer to the Face (appearance) to be used. }
  26.                 task: ProcPtr; { Callback-routine, called once per frame. If task=nil, the sprite is removed. }
  27.                 hitTask: ProcPtr; { Callback in collisions. }
  28.                 destructTask: ProcPtr; { Called when a sprite is disposed. (Usually nil.) }
  29. { SAT variables that you shouldn't change: }
  30.                 oldpos: Point;                {The 'task' routine is not allowed to change this! }
  31.                 next, prev: SpritePtr;    {You may change them in your own sorting routine, but be careful if you do.}
  32.                 r, oldr: Rect;                {Rectangle telling where to draw. Avoid messing with it.}
  33. {Variables for internal use by the sprites. Use as you please. Edit as necessary - this is merely a default}
  34. {set, enough space for most cases - but if you change the size of the record, call SetSpriteSize immediately}
  35. {after initializing (before any sprites are created)!}
  36.                 layer: integer; {For layer-sorting. When not used for that, use freely.}
  37.                 speed: Point; { Can be used for speed, but not necessarily. }
  38.                 mode: integer; { Usually used for different modes and/or to determine what image to show next. }
  39.                 appPtr: Ptr; {Pointer for use by the application - i.e. pointer to extra data}
  40.                 appLong: Longint; {Longint for free use by the application.}
  41.             end;
  42.  
  43. {Type for SATs pattern utilities.}
  44.     type
  45.         SATPattern = record
  46.                 patternType: integer; {1 = Pattern, PatHandle, 2 = PixPat, PixPatHandle}
  47.                 thePat: PixPatHandle; {or PatHandle}
  48.             end; {record}
  49.         SATPatPtr = ^SATPattern;
  50.         SATPatHandle = ^SATPatPtr;
  51.  
  52. {Update list. Used internally}
  53.         UpdatePtr = ^UpdateRec;
  54.         UpdateRec = record
  55.                 updateRect: Rect;
  56.                 next: UpdatePtr;
  57.             end;
  58.  
  59. {The globals record. Some fields are important for you. These are marked with *}
  60.         SATglobalsRec = record
  61.                 wind: WindowPtr;                            {*The window that SAT draws in. }
  62.                 offSizeH, offSizeV: integer;                    {*Offscreen size, used to limit sprite positions}
  63.                 offScreen: GrafPtr;                            {*Offscreen image }
  64.                 backScreen: GrafPtr;                        {*Background image }
  65.                 offScreenGD, backScreenGD: GDHandle;    {GDevices for offScreen and backScreen.}
  66.  
  67.                 ox, oy: longint;                                {Internal}
  68.                 pict, bwpict: integer;                        {PICT id's}
  69.                 fitThePICTs: boolean;                        {Resize PICTs to fit?}
  70.                 sorting: integer;                                {Chosen sorting}
  71.                 collision: integer;                            {Chosen collision handling}
  72.                 searchWidth: integer;                        {Chosen search width}
  73.                 device: GDHandle;                            {Chosen screen}
  74.                 screen: PixMapHandle;                        {Internal}
  75.                 bounds: Rect;                                    {Internal}
  76.                 initDepth: Integer;                            {*Depth at last icon initialization}
  77.                 synchHook: ProcPtr;                            {Synch procedure}
  78.                 sRoot: SpritePtr;                                {Sprite list root}
  79.                 updateRoot: UpdatePtr;                        {Update list root}
  80.                 anyMonsters: Boolean;                        {*False when no sprites with kind < -1 are active }
  81.  
  82.                 ditherOff: CGrafPtr;                            {Internal}
  83.                 ditherOffGD: GDHandle;                        {Internal}
  84.                 iconPort: CGrafPtr;                            {Internal}
  85.                 iconPortGD: GDHandle;                        {Internal}
  86.                 iconPort2: CGrafPtr;                        {Internal}
  87.                 iconPort2GD: GDHandle;                        {Internal}
  88.                 bwIconPort: GrafPtr;                         {Internal}
  89.             end;
  90.  
  91. {Configuration types: VPositionSort and KindCollision are defaults.}
  92.     const
  93. {Sorting options}
  94.         kVPositionSort = 0;
  95.         kLayerSort = 1;
  96.         kNoSort = 2;
  97. {Collision detection options}
  98.         kKindCollision = 0;
  99.         kForwardCollision = 1;
  100.         kBackwardCollision = 2;
  101.         kNoCollision = 3;
  102.         kForwardOneCollision = 4;
  103.  
  104.     var
  105. {$J+}
  106.         gSAT: SATglobalsRec;                {Most globals in a record. See above.}
  107.         faceRoot: FacePtr;                    {Root of face list}
  108.         colorFlag: Boolean;                    {True if color QuickDraw is available.}
  109.         gSATSoundErrorProc: ProcPtr;        {Pointer to procedure to call on sound error.}
  110. {$J-}
  111.  
  112. {Initializing and customizing}
  113.     procedure ConfigureSAT (PICTfit: boolean; newSorting, newCollision, searchWidth: integer);
  114.     procedure InitSAT (pictID, bwpictID, Xsize, Ysize: integer);
  115.     procedure CustomInitSAT (pictID, bwpictID: integer; SATdrawingArea: Rect; {}
  116.                                     preloadedWind: WindowPtr; chosenScreen: GDHandle; useMenuBar, {}
  117.                                     centerDrawingArea, fillScreen, dither4bit, beSmart: Boolean);
  118. {Maintainance, background manipulation etc.}
  119.     function SATDepthChangeTest: Boolean;
  120.     procedure SATDrawPICTs (pictID, bwpictID: integer);
  121.     procedure PeekOffscreen;
  122. {Drawing}
  123.     procedure SATPlotFace (theFace: FacePtr; theGrafPtr: GrafPtr; theGDevice: GDHandle;{}
  124.                                     where: Point; fast: boolean);
  125.     procedure SATPlotFaceToScreen (theFace: FacePtr; where: Point; fast: boolean);
  126.     procedure SATCopyBits (src, dest: GrafPtr; destGD: GDHandle; {}
  127.                                     srcRect, destRect: Rect; fast: Boolean);
  128.     procedure SATCopyBitsToScreen (src: GrafPtr; srcRect, destRect: Rect; fast: Boolean);
  129.     procedure SATBackChanged (r: Rect); {Tell SAT about changes in backScreen}
  130. {SetPort replacements}
  131.     procedure SATGetPort (var port: GrafPtr; var device: GDHandle);
  132.     procedure SATSetPort (port: GrafPtr; device: GDHandle);
  133.     procedure SATSetPortOffScreen; {Use before using QuickDraw on offScreen}
  134.     procedure SATSetPortBackScreen; {Use before using QuickDraw on backScreen}
  135.     procedure SATSetPortScreen; {Use to set port to gSAT.wind}
  136. {Sprite handling}
  137.     function GetFace (resNum: integer): FacePtr;
  138.     procedure DisposeFace (theFace: FacePtr);
  139.     function NewSprite (kind, hpos, vpos: integer; setup: ProcPtr): SpritePtr;
  140.     function NewSpriteAfter (afterthis: SpritePtr; kind, hpos, vpos: integer; setup: ProcPtr): SpritePtr;
  141.     procedure KillSprite (who: Spriteptr);
  142. {Animating}
  143.     procedure RunSAT (fast: Boolean); {The heart of the whole package!}
  144. {Special functions for advanced programmers}
  145.     procedure SATInstallSynch (theSynchProc: ProcPtr);
  146.     procedure SATInstallEmergency (theEmergencyProc: ProcPtr);
  147.     procedure SATSetSpriteRecSize (theSize: longint);
  148.     procedure SkipSAT;
  149.     procedure KillSAT; {Dispose of offscreen buffers to allow re-init}
  150. {Offscreen - use only if you need an *extra* offscreen buffer. These calls are likely to change in the future!}
  151.     procedure SATMakeOffscreen (var portP: GrafPtr; rectP: Rect; var retGDevice: GDHandle); {Make offscreen buffer in current screen depth and CLUT.}
  152.     procedure SATDisposeOffScreen (var portP: GrafPtr; theGDevice: GDHandle); {Get rid of offscreen}
  153.     function CreateOffScreen (bounds: Rect; depth: Integer; colors: CTabHandle; var retPort: CGrafPtr; var retGDevice: GDHandle): OSErr; {From Principia Offscreen - color only}
  154.     procedure DisposeOffScreen (doomedPort: CGrafPtr; doomedGDevice: GDHandle);{From Principia Offscreen - color only}
  155. {New procedures}
  156.     procedure SetPortMask (theFace: FacePtr);
  157.     procedure SetPortFace (theFace: FacePtr);
  158.     procedure SetPortFace2 (theFace: FacePtr);
  159.     function NewFace (faceBounds: Rect): FacePtr;
  160.     procedure ChangedFace (theFace: FacePtr);
  161.     procedure SATSetStrings (ok, yes, no, quit, memerr, noscreen, nopict, nowind: Str255);
  162.     function TrapAvailable (theTrap: Integer): Boolean;
  163.     function SATGetCicn (cicnId: integer): CIconHandle;
  164.     procedure SATPlotCicn (theCicn: CIconHandle; dest: GrafPtr; destGD: GDHandle; r: Rect); {Borde jag lägga till device?}
  165.     procedure SATDisposeCicn (theCicn: CIconHandle);
  166.  
  167. {Utilities}
  168.     procedure DrawInt (i: integer);
  169.     procedure DrawLong (l: longint);
  170.     function Rand (n: integer): integer;
  171.     function Rand10: integer;
  172.     function Rand100: integer;
  173.     procedure ReportStr (str: str255);
  174.     function QuestionStr (str: str255): Boolean;
  175.     function SATFakeAlert (s1, s2, s3, s4: Str255; nButtons, defButton, cancelButton: integer;{}
  176.                                     t1, t2, t3: Str255): integer;
  177.     procedure CheckNoMem (p: Ptr); {If the Ptr is nil, out of memory emergency exit}
  178.     procedure SetMouse (where: point);
  179. {Pattern utilities}
  180.     procedure SATPenPat (SATpat: SATPatHandle);
  181.     procedure SATBackPat (SATpat: SATPatHandle);
  182.     function SATGetPat (patID: integer): SATPatHandle;
  183.     procedure SATDisposePat (SATpat: SATPatHandle);
  184. {Menu bar utilities}
  185.     procedure ShowMBar;
  186.     procedure HideMBar (wind: WindowPtr);
  187. {Sound}
  188.     procedure SATSoundInit; {Called from InitSAT}
  189.     procedure SATSoundPlay (TheSound: Handle; Priority: integer; CanWait: boolean);
  190.     procedure SATSoundEvents; {Call this once in a while when not calling RunSAT often}
  191.     procedure SATSoundShutup; {Silence, dispose of sound channel}
  192.     procedure SATSoundOn;
  193.     procedure SATSoundOff;
  194.     function SATSoundDone: Boolean; {Any sound going on ?}
  195.     function SATGetSound (sndId: integer): handle;        { To load a sound and get a handle for SATSoundPlay }
  196.     function SATGetNamedSound (name: Str255): Handle; { Same but using resource names }
  197.     procedure SATDisposeSound (theSnd: handle);
  198. {Multi-channel sound routines}
  199.     function SATSoundInitChannels (num: integer): integer;
  200.     function SATSoundDoneChannel (chanNum: integer): Boolean;
  201.     procedure SATSoundPlayChannel (theSound: Handle; chanNum: integer);
  202.     procedure SATSoundReserveChannel (chanNum: integer; reserve: Boolean);
  203.     procedure SATSoundShutupChannel (chanNum: integer);
  204.     procedure SATPreloadChannels;
  205. {Experimental, likely to be renamed/removed/changed:}
  206.     procedure SATSoundPlay2 (theSound: Handle; priority: integer; canWait, skipIfSame: Boolean);
  207.     procedure SATSoundPlayEasy (theSound: Handle; canWait: Boolean);
  208.  
  209. implementation
  210. end.